import { Service } from 'egg';
import {RtcTokenBuilder}  from 'agora-access-token';

/**
 * Test Service
 */
export default class Test extends Service {

  /**
   * sayHi to you
   * @param name - your name
   */
  public async sayHi(name: string) {
    return `hi, ${name}`;
  }
  

  public async setToken(data:any){
    console.log(data)
    console.log(data)
      const appID = 'f28f52a2b05c49aab080f8d3bddd8b58';
      const appCertificate = 'cd5da9bbc2e84d0ca7769038a2d4b469';
      const channelName = data.channelName;
      const uid = data.uid
      //const account = "2882341273";
      const role = 1 ;
      
      const expirationTimeInSeconds = 60*60*24
      
      const currentTimestamp = Math.floor(Date.now() / 1000)
      
      const privilegeExpiredTs = currentTimestamp + expirationTimeInSeconds
      
      // IMPORTANT! Build token with either the uid or with the user account. Comment out the option you do not want to use below.
      
      // Build token with uid
      const tokenA = RtcTokenBuilder.buildTokenWithUid(appID, appCertificate, channelName, uid, role, privilegeExpiredTs);
      console.log(tokenA)
      return tokenA

  }
}
